package models.dao;

import models.entities.ModuleResource;
import models.repo.IRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ModuleResourceDAO {
	@Autowired
	private IRepository repo;
	
	public ModuleResource createModuleResource(ModuleResource moduleResource) throws Exception {
		if (moduleResource == null) {
			throw new IllegalArgumentException("ModuleResource");
		}

		repo.create(moduleResource);
		
		return repo.getEntityById(ModuleResource.class, moduleResource.getResourceId());
	}

	public void deleteModuleResource(ModuleResource moduleResource) throws Exception {
		if (moduleResource == null) {
			throw new IllegalArgumentException("ModuleResource");
		}
		repo.delete(moduleResource);
		
	}

	public ModuleResource getModuleResourceById(Long id) throws Exception {
		return repo.getEntityById(ModuleResource.class, id);
	}
	
	
	public void updateShop(ModuleResource moduleResource) throws Exception {
		if (moduleResource == null) {
			throw new IllegalArgumentException("shop");
		}
		
		repo.update(moduleResource);
	}
}
